

<template>

  <div >

    

        <el-popover
          placement="bottom-end"
          v-model="params.show"
          trigger="focus"
        >
          <el-input
            :placeholder="setSelectInputv1.placeholder"
            slot="reference"
            v-model="setSelectInputv1.keyword"
            :size="size"
            @input="getSeach()"
          >
             <i v-if="icon" slot="suffix" class="el-input__icon el-icon-search"></i>
          </el-input>


          <el-table
            v-loading="params.loading"
            @current-change="querySelect"
            highlight-current-row
            height="300"
         
            :data="
              params.data.filter(
                (data) =>
                  !setSelectInputv1.keyword ||
                  data.Name_B
                    .toLowerCase()
                    .includes(setSelectInputv1.keyword.toLowerCase())
              )
            "
          > 
          
           <template v-for="(item, index) in setSelectInputv1.list">
             <el-table-column  :prop="item.prop" :label="item.label"  :width="item.width"> </el-table-column>
           </template>
          <!-- <el-table-column type="index" label="序号" width="50">
            </el-table-column>
           -->
          </el-table> 

           <el-pagination
            :current-page="params.page"
            :page-size="params.limit"
            @current-change="selectPage"
            :total="params.count"
            layout="prev, pager, next"
          >
          </el-pagination>
        </el-popover>
     
</div>
</template>
<script>
let t;

import ViewTitle from "@/forComponents/viewTitle/index.vue";
import { mapState, mapActions } from "vuex";
export default {
    //  size medium / small / mini
  props: ["setSelectInputv1",'size','icon'],
  data() {
    return {

     

      params: {
          show:false,

            page: 1,
           limit: 20,
           loading:false,
            data: [],
            count: 0,
         
      },
   
   
    };
  },
  mounted() {
    t = this;
   

    t.getList()

  },

  methods: {
    

    getSeach(){
       this.params.page=1;
       this.getList()
    },

    getList() {
      this.params.loading = true;
      let d = {
        keyword: this.setSelectInputv1.keyword,
        page: this.params.page,
        limit: this.params.limit,
      };
      if(t.setSelectInputv1.key=='huajia_patient'){
        d.register_doctor=1;
        d.status=3;
      }
      t["_API"][t.setSelectInputv1.url](d).then((res) => {
        this.params.loading = false;
        console.log("ress",res)
        if (res.code == 200) {

            switch (t.setSelectInputv1.key) {
              case 'yisheng':
                 this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.doctor.real_name,
                      Id_B:v.doctor.id,
                      ...v,
                    }
                  });
               break;
               case 'mantebing':
                  this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.name,
                      Id_B:v.m_code,
                      ...v,
                    }
                  });
               break;
                  case 'patient':
                  this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.name,
                      Id_B:v.id,
                      ...v,
                    }
                  });
               break;
                 case 'zhengduan':
                  this.params.data = res.data.map(v=>{
                    return {
                      Name_B:v.name,
                      Id_B:v.id,
                      ...v,
                    }
                  });
               break;
                 case 'huajia_patient':
                  
                  this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.member_info.name,
                      Id_B:v.member_info.id,
                      ...v,
                    }
                  });
               break;
                 case 'drugs':
                  
                  this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.name,
                      Id_B:v.id,
                      ...v,
                    }
                  });
               break;
              default:
                 this.params.data = res.data.list.map(v=>{
                    return {
                      Name_B:v.real_name,
                      Id_B:v.id,
                      ...v,
                    }
                  });
                break;
            }

          console.log(" this.params.data ", this.params.data )

          this.params.count = res.data.count;
        }
      });
    },

    selectPage(e) {
      this.params.page = e;
      this.getList();
    },

    querySelect(item) {
        if(!item){
            return 
        }
        console.log("item",item)
         this.setSelectInputv1.keyword = item.Name_B;
         this.setSelectInputv1.id= item.Id_B;
       
          //诊断
          if(t.setSelectInputv1.key=='zhengduan'){
               this.setSelectInputv1.code=item.code;
          }
           if(t.setSelectInputv1.key=='huajia_patient'){
               this.setSelectInputv1.detail=item;
              
          }
          
        if(t.setSelectInputv1.key=='drugs'){
             this.setSelectInputv1.keyword='';
             this.setSelectInputv1.id='';
             
               if (this.setSelectInputv1.detail.findIndex((res) => res.id == item.id) === -1) {
                    this.setSelectInputv1.detail = this.setSelectInputv1.detail.concat(item);
                }
                console.log("this.setSelectInputv1.detail",this.setSelectInputv1.detail)
          }
      this.params.show = false;
    },
  },



};
</script>
<style lang='scss' scoped>

</style>